Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace public_key_registry from cis3_sponsored_transaction with corresponding smart contract features #318

Closed
wants to merge 1 commit into from

Conversation

DOBEN
Copy link
Member

@DOBEN DOBEN commented Jul 14, 2023

Purpose

addresses #258

After the new protocol update P6, smart contracts can now get the public_keys of accounts within the smart contract code. There is also a new check_account_signature function available.

The public_key_registry is not necessary anymore in the sponsored transaction smart contract and should be replaced.

Note: This PR is a draft and has some local dependencies hardcoded to simplify the use of a "local/unreleased" smart contract testing integration library. This needs to be updated/changed before merging.
https://github.com/Concordium/concordium-smart-contract-tools/tree/main/concordium-smart-contract-testing

Changes

  • Remove public_key_registry.
  • Add check_account_signature to verify the signature in the smart contract.
  • Replace old publicKeyOf function (returned a tuple pair (public key, nonce)) with two separate functions publicKeyOf (returns public keys for a vector of accounts) and nonceOf (returns nonces for a vector of accounts).
  • Add integration tests.
  • Add integration testings for a signature transfer permit function call.
  • Add integration testings for a signature update operator permit function call.
  • Signature/PublicKey types were removed from concordium_std and are now available via concordium_contracts_common.

@abizjak abizjak changed the base branch from main to acc-sig-checksd July 15, 2023 08:34
@abizjak abizjak force-pushed the acc-sig-checksd branch 2 times, most recently from d9d1177 to 6954787 Compare July 15, 2023 12:37
Base automatically changed from acc-sig-checksd to main July 15, 2023 12:52
examples/cis3-nft-sponsored-txs/Cargo.toml Outdated Show resolved Hide resolved
examples/cis3-nft-sponsored-txs/src/lib.rs Outdated Show resolved Hide resolved
examples/cis3-nft-sponsored-txs/src/lib.rs Outdated Show resolved Hide resolved
@DOBEN DOBEN requested review from abizjak and limemloh July 17, 2023 15:16
@DOBEN DOBEN force-pushed the 258-use-public-keys branch 2 times, most recently from 47d95ba to 5f39029 Compare August 7, 2023 10:06
examples/cis3-nft-sponsored-txs/README.md Outdated Show resolved Hide resolved
@@ -22,8 +22,8 @@ quickcheck = {version = "1", optional = true }
getrandom = { version = "0.2", features = ["custom"], optional = true }

[dependencies.concordium-contracts-common]
path = "../concordium-contracts-common/concordium-contracts-common"
version = "7.0"
path = "../../../LocalTestingLibrary/concordium-smart-contract-tools/concordium-base/concordium-contracts-common/concordium-contracts-common"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still not sure what the best option for this is. Once we release the libraries we can use the published ones for this PR, but we should also try to think about a long-term solution.

Comment on lines +60 to +85
let mut inner_key_map: BTreeMap<KeyIndex, VerifyKey> = BTreeMap::new();

inner_key_map.insert(
KeyIndex(0u8),
VerifyKey::Ed25519VerifyKey(
ed25519_dalek::PublicKey::from_bytes(&PUBLIC_KEY)
.expect("Should be able to create public key"),
),
);

let credential_public_keys = CredentialPublicKeys {
keys: inner_key_map,
threshold: SignatureThreshold::ONE,
};

let mut key_map: BTreeMap<CredentialIndex, CredentialPublicKeys> = BTreeMap::new();
key_map.insert(
CredentialIndex {
index: 0u8,
},
credential_public_keys,
);

let keys = AccountAccessStructure {
keys: key_map,
threshold: AccountThreshold::ONE,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut inner_key_map: BTreeMap<KeyIndex, VerifyKey> = BTreeMap::new();
inner_key_map.insert(
KeyIndex(0u8),
VerifyKey::Ed25519VerifyKey(
ed25519_dalek::PublicKey::from_bytes(&PUBLIC_KEY)
.expect("Should be able to create public key"),
),
);
let credential_public_keys = CredentialPublicKeys {
keys: inner_key_map,
threshold: SignatureThreshold::ONE,
};
let mut key_map: BTreeMap<CredentialIndex, CredentialPublicKeys> = BTreeMap::new();
key_map.insert(
CredentialIndex {
index: 0u8,
},
credential_public_keys,
);
let keys = AccountAccessStructure {
keys: key_map,
threshold: AccountThreshold::ONE,
};
let rng = &mut rand::thread_rng();
let keypairs = AccountKeys::singleton(rng);
let keys: AccountAccessStructure = (&keypairs).into();

Comment on lines +143 to +148
let mut inner_signature_map = BTreeMap::new();
inner_signature_map.insert(0u8, concordium_std::Signature::Ed25519(SIGNATURE_UPDATE_OPERATOR));

let mut signature_map = BTreeMap::new();
signature_map.insert(0u8, CredentialSignatures {
sigs: inner_signature_map,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we unify AccountSignature and TransactionSignature this will become

let signature = keypairs.sign(&to_bytes(...))

Comment on lines +267 to +264
let mut inner_key_map: BTreeMap<u8, PublicKey> = BTreeMap::new();

inner_key_map.insert(0u8, PublicKey::Ed25519(concordium_std::PublicKeyEd25519(PUBLIC_KEY)));

let credential_public_keys = concordium_std::CredentialPublicKeys {
keys: inner_key_map,
threshold: SignatureThreshold::ONE,
};

let mut key_map: BTreeMap<u8, concordium_std::CredentialPublicKeys> = BTreeMap::new();
key_map.insert(0u8, credential_public_keys);

let account_public_keys: AccountPublicKeys = AccountPublicKeys {
keys: key_map,
threshold: AccountThreshold::ONE,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut inner_key_map: BTreeMap<u8, PublicKey> = BTreeMap::new();
inner_key_map.insert(0u8, PublicKey::Ed25519(concordium_std::PublicKeyEd25519(PUBLIC_KEY)));
let credential_public_keys = concordium_std::CredentialPublicKeys {
keys: inner_key_map,
threshold: SignatureThreshold::ONE,
};
let mut key_map: BTreeMap<u8, concordium_std::CredentialPublicKeys> = BTreeMap::new();
key_map.insert(0u8, credential_public_keys);
let account_public_keys: AccountPublicKeys = AccountPublicKeys {
keys: key_map,
threshold: AccountThreshold::ONE,
};
let account_public_keys = (&keypairs).into();

Copy link
Collaborator

@limemloh limemloh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first version only supported accounts with one key, and the reason I remember for this was to simplify the endpoints for registering keys. So now that we are removing those endpoints, I think we should support multi-sig accounts here

concordium-cis2/src/lib.rs Outdated Show resolved Hide resolved
examples/cis3-nft-sponsored-txs/src/lib.rs Outdated Show resolved Hide resolved
examples/cis3-nft-sponsored-txs/src/lib.rs Outdated Show resolved Hide resolved
examples/cis3-nft-sponsored-txs/src/lib.rs Outdated Show resolved Hide resolved
examples/cis3-nft-sponsored-txs/src/lib.rs Outdated Show resolved Hide resolved
examples/cis3-nft-sponsored-txs/src/lib.rs Outdated Show resolved Hide resolved
@DOBEN DOBEN mentioned this pull request Aug 11, 2023
@DOBEN
Copy link
Member Author

DOBEN commented Nov 23, 2023

close as completed in
#363
#359

@DOBEN DOBEN closed this Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants